<?php
// +----------------------------------------------------------------------
// | 幕小铺
// +----------------------------------------------------------------------
// | 版权所有 2016~2020 幕小铺科技（大连）有限公司
// +----------------------------------------------------------------------
// | 2020/03/14
// +----------------------------------------------------------------------

namespace app\user_center\datacache;
use think\Model;
use think\facade\Cache;

/**
 * 用户 缓存层
 * @package app\user_center\model
 */
class Member{

    /**
     * 用户的 视频缓存池
     * @param uid int 用户id
     * @param limit 获取池子大小 默认500条
     * @param cache 是否更新 缓存
     * @author jason wang <120907037@qq.com>
     * @return array
     */
    public function getListByUid($uid, $limit = 500, $cache = false){
        $cacheName = 'play_list_uid_'.$uid.'_'.$limit;//dump(!Cache::get($cacheName));
        if(!Cache::get($cacheName) || $cache){//dump($cache);
            $map = [];
            $map['uid']	= $uid;
            $map['play_operation_status']	= 1;
            $list = model('video/VideoPlay') -> where($map) ->limit($limit) -> order('create_time desc') -> select() ->toArray();//用户视频池
            if(!empty($list)){
                Cache::set($cacheName, $list, 60*60*24*7);//默认缓存7天
            }
        }
        return Cache::get($cacheName);
    }
	
	
	/**
     * 用户的 搜索缓存池
     * @param uid int 用户id
     * @param user_name string 用户名
     * @param limit 获取池子大小 默认500条
     * @param cache 是否更新 缓存
     * @author jason wang <120907037@qq.com>
     * @return array
     */
    public function getListByUserNameSearch($uid, $user_name, $limit = 500, $cache = true){
        $cacheName = 'search_get_list_user_name_'.$user_name.'_'.$limit;
        if(!Cache::get($cacheName) || $cache){
            $map = [
				['uid' , 'neq', $uid],
				['nick_name' , 'like', '%'. $user_name .'%'],
			];
            $list = model('user_center/Member', 'model\user') -> where($map) ->limit($limit) -> order('create_time desc') -> select() ->toArray();//用户搜索池
            Cache::set($cacheName, $list, 60*60);//默认缓存7天
        }
        return Cache::get($cacheName) ? Cache::get($cacheName) : [];
    }


}
